package jfox.platform.organization.bo;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;

import jfox.platform.organization.dao.DepartmentDAO;
import jfox.platform.organization.entity.Department;
import jfox.platform.infrastructure.DataAccessObject;
import jfox.platform.infrastructure.EntityNotExistedException;
import jfox.platform.infrastructure.SuperBO;
/**
 * @author <a href="mailto:sheshengdian@gmail.com">sheshengdian</a>
 */
@Stateless
@Local
public class DepartmentBOBean extends SuperBO implements DepartmentBO{
    @EJB
    DepartmentDAO departmentDAO;

    public DataAccessObject getDataAccessObject() {
        return departmentDAO;
    }

    public void newDepartment(Department department) {
    	departmentDAO.insertDepartment(department);
    }

    public void deleteDepartment(long id) {
    	Department department = departmentDAO.getDepartmentById(id);
    	// department 不存在
        if(department == null){
            throw new EntityNotExistedException(Department.class, id);
        }
        // 判断 Node 是否被引用
        checkEntityReferenced(department);
        departmentDAO.deleteDepartment(id);
    }

    public void updateDepartment(Department department) {
    	departmentDAO.updateDepartment(department);
    }

    public Department getDepartmentById(long id) {
        return departmentDAO.getDepartmentById(id);
    }
    public Department getDepartmentByCompany(long companyId) {
        return departmentDAO.getDepartmentByCompany(companyId);
    }
    public List<Department> getAllDepartments() {
        return departmentDAO.getAllDepartments();
    }

    public void addFunction(){
        
    }
}
